package com.xxxx.blog.service.serviceImpl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xxxx.blog.entity.Channel;
import com.xxxx.blog.mapper.ChannelMapper;
import com.xxxx.blog.service.ChannelService;
import com.xxxx.blog.utils.Maps;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@AllArgsConstructor
@Service
public class ChannelServiceImpl extends ServiceImpl<ChannelMapper,Channel> implements ChannelService {

    private ChannelMapper channelMapper;

    public int create(Channel channel){
        return channelMapper.create(channel);
    }

    public int delete(Integer id){
        return channelMapper.delete(Maps.build(id).getMap());
    }

    public int update(Channel channel){
        return channelMapper.update(Maps.build(channel.getId()).beanToMapForUpdate(channel));
    }

    public PageInfo<Channel> query(Channel channel){
        if(channel != null && channel.getPage() != null){
            PageHelper.startPage(channel.getPage(),channel.getLimit());
        }
        List<Channel> list = channelMapper.query(Maps.build().beanToMap(channel));
        return new PageInfo<Channel>(list);
    }

    public List<Channel> getChannelByPos(String pos){
        List<Channel> list = channelMapper.query(Maps.build().put("pos",pos).getMap());
        return list;
    }

    public List<Channel> all(){
        List<Channel> list = channelMapper.query(Maps.build().getMap());
        return list;
    }

    public Channel detail(Integer id){
        return channelMapper.detail(Maps.build(id).getMap());
    }

    public int count(Channel channel){
        return channelMapper.count(Maps.build().beanToMap(channel));
    }




}
